#include<iostream>
using namespace std;
class Person {
public:
	Person(string _name,int _age):name(_name),age(_age){}
	void display() {
		cout << name << ' ' << age << ' ';
	}
protected:
	string name;
	int age;
};
class Listen :public Person {
public:
	Listen(string _name, int _age, int _daily, int _test) :Person(_name, _age),daily(_daily),test(_test) {
		double _score = 0.4 * daily + 0.6 * test;
		if ((int)_score < 60) {
			score = 'F';
		}
		else if((int)_score < 65){
			score = 'D';
		}
		else if ((int)_score < 75) {
			score = 'C';
		}
		else if ((int)_score < 85) {
			score = 'B';
		}
		else {
			score = 'A';
		}
	}
	void display() {
		cout << name << ' ' << age << ' ' << score << endl;
	}
protected:
	int daily;
	int test;
	char score;
};
class NoListen :public Person {
public:
	NoListen(string _name, int _age, int _test) :Person(_name, _age), test(_test) {
		if (test < 60) {
			score = 'F';
		}
		else if (test < 65) {
			score = 'D';
		}
		else if (test < 75) {
			score = 'C';
		}
		else if (test < 85) {
			score = 'B';
		}
		else {
			score = 'A';
		}
	}
	void display() {
		cout << name << ' ' << age << ' ' << score << endl;
	}
protected:
	char score;
	int test;
};
int main()
{
	int t;
	cin >> t;
	char type;
	string name;
	int age;
	int daily;
	int test;
	for (int i = 0; i < t; i++) {
		cin >> type >> name >> age;
		if (type == 'R') {
			cin >> daily >> test;
			Listen l(name, age, daily, test);
			l.display();
		}
		else {
			cin >> test;
			NoListen l(name, age, test);
			l.display();
		}
	}
	return 0;
}